-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add AsyncSequence support for Realtime Database #15596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This change introduces Swift AsyncSequence support for Firebase Realtime Database, enabling a modern, structured concurrency approach for observing data. Key changes include: - `DatabaseQuery.snapshots`: An asynchronous sequence for value events, consistent with Firestore's `snapshots` and Android's RTDB `snapshots()`. - `DatabaseQuery.childEvents()`: An asynchronous sequence for child events (`childAdded`, `childChanged`, `childRemoved`, `childMoved`), consistent with Android's RTDB `childEvents()`. - Implementation uses the `AsyncIteratorProtocol` pattern, aligning with the Firestore SDK for `Sendable` compliance and lazy listener initialization. - `DatabaseQuery` is marked `@retroactive @unchecked Sendable` to resolve concurrency warnings. - The `handles` array in `DatabaseChildEventsSequence.Iterator.init` is explicitly captured by value in `onTermination` to prevent concurrency issues. - Added usage tests to `DatabaseAPITests.swift`. - Refactored Sendable conformances to be grouped together for better readability.
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
Generated by 🚫 Danger |
laike9m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great addition to the Realtime Database SDK, providing a modern Swift Concurrency interface for observing data changes. The implementation follows the established patterns in the Firebase Apple SDKs.
I have one minor suggestion regarding Sendable conformance for the DatabaseEvent enum.
| // MARK: - DatabaseEvent | ||
|
|
||
| /// An enumeration of granular child-level events. | ||
| public enum DatabaseEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DatabaseEvent enum should explicitly conform to Sendable. Since it is a public enum used as the element type of an AsyncSequence, explicit conformance ensures it can be safely used across concurrency boundaries in strict mode. Note that DataSnapshot is already marked NS_SWIFT_SENDABLE in its header, so the enum will satisfy the requirements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion.
Interesting: given the symbol, DataSnapshot, in a Swift context, it recognized that the symbol was being bridged from Objective-C and the source-of-truth definition was marked sendable.
FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDataSnapshot.h- */
FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDataSnapshot.h-NS_SWIFT_SENDABLE
FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDataSnapshot.h:NS_SWIFT_NAME(DataSnapshot)
FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDataSnapshot.h-@interface FIRDataSnapshot : NSObject
FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDataSnapshot.h-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, from the trace the agent did read FIRDataSnapshot.h so it had the context.
This change introduces Swift AsyncSequence support for Firebase Realtime Database, enabling a modern, structured concurrency approach for observing data.
Key changes include:
DatabaseQuery.snapshots: An asynchronous sequence for value events, consistent with Firestore'ssnapshotsand Android's RTDBsnapshots().DatabaseQuery.childEvents(): An asynchronous sequence for child events (childAdded,childChanged,childRemoved,childMoved), consistent with Android's RTDBchildEvents().AsyncIteratorProtocolpattern, aligning with the Firestore SDK forSendablecompliance and lazy listener initialization.DatabaseQueryis marked@retroactive @unchecked Sendableto resolve concurrency warnings.handlesarray inDatabaseChildEventsSequence.Iterator.initis explicitly captured by value inonTerminationto prevent concurrency issues.DatabaseAPITests.swift.